<?php

class Mline extends CI_Model {

    private $_table = 'line';
    public function __construct() {
        parent::__construct();
    }
    
    /**
     * Get the list of stations
     */
    public function listAllLines($record=null, $start=null, $order=null) {
        if ($record != null && $start != null) {
            $this->db->limit($record, $start);
        }
        if ($order != null) {
            $this->db->order_by($order);   
        }
        return $this->db->get($this->_table)->result_array();
    }
    
    public function insertLine($data_insert) {
        $this->db->insert($this->_table, $data_insert);
        return $this;
    }
    
    public function updateLine($data_update, $id) {
        $this->db->where('id', $id);
        $this->db->update($this->_table,$data_update);
        return $this;
    }
    
    public function deleteLine($id) {
        $this->db->where('id', $id)->delete($this->_table);
        return $this;
    }
    
    public function getLineByName($name) {
        return $this->db->where('code', $name)->get($this->_table)->num_rows();
    }
    
    public function countAll() {
        return $this->db->count_all($this->_table);
    }
    
    public function getLineById($id) {
        return $this->db->where('id', $id)->get($this->_table)->row_array();
    }

}